<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of move_pattern_to_hd</title>
  <meta name="keywords" content="move_pattern_to_hd">
  <meta name="description" content="Moves the pattern MAT to the hard disk">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<!-- menu.html . -->
<h1>move_pattern_to_hd
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>Moves the pattern MAT to the hard disk</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [subj pathfilename] = move_pattern_to_hd(subj,patname,varargin) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> Moves the pattern MAT to the hard disk

 [SUBJ PATHFILENAME] = MOVE_PATTERN_TO_HD(SUBJ,PATNAME,...)

 Saves the pattern MAT field as a file, and removes the mat field
 from the pattern cell, to save hard disk space. It also adds a field
 'movehd' to the patterns cell saying where the pattern was stored so
 that getpatterns can transparently retrieve the pattern from the
 hard disk. In other words, you can continue working with this
 pattern *as though* it was still stored in the SUBJ structure

 SUBDIR (optional, default = subj.header.subdir, which
 defaults to '.'). An optional parameter that says where to save the
 file. Do not include a file separator at the end

 Need to figure out a better way to deal with multiple files with
 the same name than just the datetime(seconds) - should
 auto-rename - xxx. Also, this shouldn't take in a filename from
 the user, since it should be invisible to them.

 N.B. At the moment, you can only move patterns to the HD, which
 makes sense since they're the biggest RAM hogs. However, the
 get/set_mat scripts would work fine if you were to move an
 object of a different type, so it may/not be worth generalising
 this to move_object_to_hd... xxx</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="add_history.html" class="code" title="function [subj] = add_history(subj,objtype,objname,hist_str,displayme)">add_history</a>	Adds HIST_STR to OBJNAME's history field.</li><li><a href="datetime.html" class="code" title="function [dt] = datetime(seconds)">datetime</a>	Spits out the date and time in yymmdd_HHMM format</li><li><a href="exist_objfield.html" class="code" title="function [isthere] = exist_objfield(subj,objtype,objname,fieldname)">exist_objfield</a>	Checks whether the field exists</li><li><a href="get_mat.html" class="code" title="function [mat] = get_mat(subj,objtype,objname)">get_mat</a>	Returns the MAT field of the object</li><li><a href="get_objsubfield.html" class="code" title="function [val] = get_objsubfield(subj,objtype,objname,fieldname,subfieldname)">get_objsubfield</a>	Returns the subfield for this object</li><li><a href="propval.html" class="code" title="function [combined_struct user_struct undefaulted_struct] = propval(user_propvals,defaults_struct)">propval</a>	This deals with property/value pairs of optional arguments.</li><li><a href="remove_mat.html" class="code" title="function [subj] = remove_mat(subj,objtype,objname)">remove_mat</a>	Sets the mat field of the OBJNAME of OBJTYPE to empty.</li><li><a href="set_objfield.html" class="code" title="function [subj] = set_objfield(subj,objtype,objname,fieldname,newval,varargin)">set_objfield</a>	Replace or add a field to an object</li></ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [subj pathfilename] = move_pattern_to_hd(subj,patname,varargin)</a>
0002 
0003 <span class="comment">% Moves the pattern MAT to the hard disk</span>
0004 <span class="comment">%</span>
0005 <span class="comment">% [SUBJ PATHFILENAME] = MOVE_PATTERN_TO_HD(SUBJ,PATNAME,...)</span>
0006 <span class="comment">%</span>
0007 <span class="comment">% Saves the pattern MAT field as a file, and removes the mat field</span>
0008 <span class="comment">% from the pattern cell, to save hard disk space. It also adds a field</span>
0009 <span class="comment">% 'movehd' to the patterns cell saying where the pattern was stored so</span>
0010 <span class="comment">% that getpatterns can transparently retrieve the pattern from the</span>
0011 <span class="comment">% hard disk. In other words, you can continue working with this</span>
0012 <span class="comment">% pattern *as though* it was still stored in the SUBJ structure</span>
0013 <span class="comment">%</span>
0014 <span class="comment">% SUBDIR (optional, default = subj.header.subdir, which</span>
0015 <span class="comment">% defaults to '.'). An optional parameter that says where to save the</span>
0016 <span class="comment">% file. Do not include a file separator at the end</span>
0017 <span class="comment">%</span>
0018 <span class="comment">% Need to figure out a better way to deal with multiple files with</span>
0019 <span class="comment">% the same name than just the datetime(seconds) - should</span>
0020 <span class="comment">% auto-rename - xxx. Also, this shouldn't take in a filename from</span>
0021 <span class="comment">% the user, since it should be invisible to them.</span>
0022 <span class="comment">%</span>
0023 <span class="comment">% N.B. At the moment, you can only move patterns to the HD, which</span>
0024 <span class="comment">% makes sense since they're the biggest RAM hogs. However, the</span>
0025 <span class="comment">% get/set_mat scripts would work fine if you were to move an</span>
0026 <span class="comment">% object of a different type, so it may/not be worth generalising</span>
0027 <span class="comment">% this to move_object_to_hd... xxx</span>
0028 
0029 
0030 <span class="comment">% Catch user error early</span>
0031 <span class="keyword">if</span> ~nargout
0032   error(<span class="string">'Don''t forget to catch the subj structure that gets returned'</span>);
0033 <span class="keyword">end</span>
0034 
0035 <span class="keyword">if</span> strcmp(patname,<span class="string">'pattern'</span>)
0036   error(<span class="string">'You don''t have to feed an objtype argument to move_pattern_to_hd'</span>);
0037 <span class="keyword">end</span>
0038 
0039 <span class="comment">% Deal with optional arguments</span>
0040 defaults.subdir = <a href="get_objsubfield.html" class="code" title="function [val] = get_objsubfield(subj,objtype,objname,fieldname,subfieldname)">get_objsubfield</a>(subj,<span class="string">'subj'</span>,<span class="string">''</span>,<span class="string">'header'</span>,<span class="string">'subdir'</span>);
0041 args = <a href="propval.html" class="code" title="function [combined_struct user_struct undefaulted_struct] = propval(user_propvals,defaults_struct)">propval</a>(varargin,defaults);
0042 
0043 <span class="comment">% Check hasn't alredy been moved to hard disk</span>
0044 <span class="keyword">if</span> <a href="exist_objfield.html" class="code" title="function [isthere] = exist_objfield(subj,objtype,objname,fieldname)">exist_objfield</a>(subj,<span class="string">'pattern'</span>,patname,<span class="string">'movehd'</span>)
0045   disp( sprintf(<span class="string">'Patterns %s already moved to hard disk - returning'</span>,patname) );
0046   pathfilename = <span class="string">''</span>;
0047   <span class="keyword">return</span>
0048 <span class="keyword">end</span>
0049 
0050 dt = <a href="datetime.html" class="code" title="function [dt] = datetime(seconds)">datetime</a>(true);
0051 
0052 <span class="comment">% Won't overwrite an existing file of same name</span>
0053 pathfilename = sprintf(<span class="string">'%s/%s_%s'</span>,args.subdir,patname,dt);
0054 <span class="keyword">if</span> exist(pathfilename, <span class="string">'file'</span>)
0055   error( sprintf(<span class="string">'A file called %s already exists'</span>,pathfilename) );
0056 <span class="keyword">end</span>
0057 
0058 <span class="comment">% Make subdirectory if necessary</span>
0059 <span class="keyword">if</span> ~exist(args.subdir,<span class="string">'dir'</span>)
0060   mkdir(args.subdir);
0061 <span class="keyword">end</span>
0062 
0063 <span class="comment">% Save the contents to the HD and remove from the SUBJ</span>
0064 mat = <a href="get_mat.html" class="code" title="function [mat] = get_mat(subj,objtype,objname)">get_mat</a>(subj,<span class="string">'pattern'</span>,patname);
0065 matsize = size(mat);
0066 save(pathfilename,<span class="string">'mat'</span>);
0067 subj = <a href="remove_mat.html" class="code" title="function [subj] = remove_mat(subj,objtype,objname)">remove_mat</a>(subj,<span class="string">'pattern'</span>,patname);
0068 
0069 <span class="comment">% SET_MAT will set the matsize to [0 0] because it thinks we just</span>
0070 <span class="comment">% removed the MAT. rewrite the MATSIZE to faithfully record the</span>
0071 <span class="comment">% size of the MAT now residing on the hard disk</span>
0072 subj = <a href="set_objfield.html" class="code" title="function [subj] = set_objfield(subj,objtype,objname,fieldname,newval,varargin)">set_objfield</a>(subj,<span class="string">'pattern'</span>,patname,<span class="string">'matsize'</span>,matsize);
0073 
0074 <span class="comment">% Set the movehd field in the object so that we can keep track of</span>
0075 <span class="comment">% where the MAT has been stored</span>
0076 movehd.first_saved = dt;
0077 movehd.pathfilename = pathfilename;
0078 subj = <a href="set_objfield.html" class="code" title="function [subj] = set_objfield(subj,objtype,objname,fieldname,newval,varargin)">set_objfield</a>(subj,<span class="string">'pattern'</span>,patname,<span class="string">'movehd'</span>,movehd,<span class="string">'ignore_absence'</span>,true);
0079 
0080 <span class="comment">% Book-keeping (since the header and the rest of the object stays on the hard disk)</span>
0081 hist_str = sprintf(<span class="string">'Moving pattern %s to harddisk as %s'</span>,patname,pathfilename);
0082 subj = <a href="add_history.html" class="code" title="function [subj] = add_history(subj,objtype,objname,hist_str,displayme)">add_history</a>(subj,<span class="string">'pattern'</span>,patname,hist_str,true);
0083</pre></div>
<hr><address>Generated on Wed 31-Aug-2005 15:27:57 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2003</address>
</body>
</html>